<?php
include_once("functions/db_manipulate.php");

if (!init()) {
  redirect("?action=login");
}

$fliesResultSet = getAllFlies();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title><?= getMessageByKey("flies.archive.title") ?></title>
  <link rel="stylesheet" type="text/css" href="css/navigation.css">
  <link rel="stylesheet" type="text/css" href="css/square.css">
  <link rel="stylesheet" type="text/css" href="css/menu.css">
  <link rel="stylesheet" type="text/css" href="css/common.css">
  <link rel="stylesheet" type="text/css" href="css/flies.css">
  <script src="resources/jquery.js"></script>

  <meta charset="<?= getMessageByKey("default.charset") ?>">
</head>
<body class="body">

<?php
include_once("menu.php");
?>

<div id="square">
  <div class="fliesdiv">

    <?php
    $date = "";
    while ($fly = mysql_fetch_assoc($fliesResultSet)) {

      if ($fly['date'] != $date) {
        ?>
        <div class="fliesheader">
          <?= $fly['date'] ?>
        </div>
        <?php
        $date = $fly['date'];
      }


      $comments = countFlyComments($fly['id']);
      ?>
      <div class="flydiv">
        <div class="flyheader">
          <?= $fly['header'] ?>
        </div>

        <div class="flylegend">
          <?= $fly['legend'] ?>
        </div>

        <div id="flyinfo">
          <div id="author">
            <?= $fly['author'] ?>
          </div>
          <div id="date">
            <?= $fly['date'] ?>
          </div>
          <div id="date">
            <?= $fly['time'] ?>
          </div>
        </div>

        <div class="flybuttonsdiv">

          <div class="flybutton"
               onclick="location.href = '?action=likefly&fid=<?= $fly['id'] ?>&like=1'">
            <?= getMessageByKey("button.user.comment.likes") ?>(<?= $fly['likes'] ?>)
          </div>

          <div class="flybutton"
               onclick="location.href = '?action=likefly&fid=<?= $fly['id'] ?>&dislike=1'">
            <?= getMessageByKey("button.user.comment.dislikes") ?>(<?= $fly['dislikes'] ?>)
          </div>

          <div class="flybutton" onclick="location.href = '?action=showfly&fid=<?= $fly['id'] ?>'">
            <?= getMessageByKey("flies.archive.comments") ?>(<?= $comments ?>)
          </div>


        </div>
      </div>
    <?php
    }
    ?>
  </div>
</div>


<?php
include_once("navigation.php");
?>

</body>
</html>